<?php

// vgl. http://www.w3schools.com/php/php_ajax_livesearch.asp

$xmlDoc = new DOMDocument();
$xmlDoc->load("xml/AbaProj_CRM_activ.xml");

$x = $xmlDoc->getElementsByTagName('ProjectBase');

//get the q parameter from URL
$q = $_GET["q"];

//lookup all links from the xml file if length of q>0
if (strlen($q) > 0) {
    $hint = "";
    for ($i = 0; $i < ($x->length); $i++) {
        $y = $x->item($i)->getElementsByTagName('ProjName');
        $z = $x->item($i)->getElementsByTagName('ProjNr');
        if ($y->item(0)->nodeType == 1) {
            //find a link matching the search text
            if (stristr($y->item(0)->childNodes->item(0)->nodeValue, $q)) {
                if ($hint == "") {
                    
                    $abacusnummer_z_1 = $z->item(0)->childNodes->item(0)->nodeValue;
                    $abacusname_y_1 = $y->item(0)->childNodes->item(0)->nodeValue;
            
                    $hint ="<input type='button' value='$abacusname_y_1' onclick='update_AbacusNr($abacusnummer_z_1)'>";        
                   
                } else {                   
                    
                    $abacusnummer_z_1 = $z->item(0)->childNodes->item(0)->nodeValue;
                    $abacusname_y_1 = $y->item(0)->childNodes->item(0)->nodeValue;
                    
                    $hint =   $hint . "<br /><b>" .                  
                   
                    "<input type='button' value='$abacusname_y_1' onclick='update_AbacusNr($abacusnummer_z_1)'>";        
                }
            }
        }
    }
}

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "") {
    $response = "Kein Abacusprojekt mit diesen Suchparametern gefunden...";
} else {
    $response = $hint;
}

//output the response
echo $response;
?>